package contactbook.test.mock.dao;

import javax.persistence.EntityManager;

import contactbook.dao.AccountDAOInterface;
import contactbook.model.Account;

public class AccountDAOMock implements AccountDAOInterface {

	private Account account = null;
	
	@Override
	public Account create(Account account) {
		this.account = new Account(account.getLogin(), account.getPassword());
		this.account.setId(1);
		this.account.setGroups(account.getGroups());
		this.account.setContacts(account.getContacts());
		return this.account;
	}

	@Override
	public void delete(int accountId) {
		if (account.getId() == accountId) {
			account = null;
		}
	}

	@Override
	public Account findById(int accountId) {
		return (account != null && account.getId() == accountId) ? account : null;
	}
	
	@Override
	public Account findByLoginPassword(String login, String password) {
		return (account != null && account.getLogin()== login && account.getPassword() == password) ? account : null;
	}

	@Override
	public void update(Account account) {
		this.account.setLogin(account.getLogin());
		this.account.setPassword(account.getPassword());
	}
	
	@Override
	public void setEntityManager(EntityManager em) {
		// Nothing
	}
	
}
